package com.wing.cms.dao;

import java.util.List;

import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import com.wing.common.CommonSpringJDBC;
import com.wing.common.util.PageBean;
import com.wing.cms.domain.Portlet;
import com.wing.cms.domain.Portlet2;

@Repository
public class Portlet2Dao extends CommonSpringJDBC<Portlet2, String> {

	public PageBean findPageList(int currentPage, int pageSize, Object... args) {
		String where= " 1=1 ";
		String sql1=" SELECT * FROM cms_portlet2 where "+where+" ORDER BY id ASC " +
			" LIMIT "+(currentPage-1) * pageSize+","+pageSize;
		String sql2 = "select count(id) from  cms_portlet2  where"+where;
		String[] sqlArray = {sql1,sql2 };
		return super.findPageList(sqlArray, currentPage, pageSize);
	}
	
	public Portlet2 findById(String id){
		String sql ="select a.*,b.name as showprogrpTitle from cms_portletinstance2 a ,ext_productgroup b where a.productgroupId = b.id and a.Id = ? ";
		List list = super.getSimpleJdbcTemplate().queryForList(sql,id);
		if(list.size()==0){
			return null;
		}
		return super.getSimpleJdbcTemplate().queryForObject(sql, ParameterizedBeanPropertyRowMapper
						.newInstance(Portlet2.class), id);
	}
}
